anonymous function variable scope [js, ajax]

Posted by arthurprs on Stack Overflow See other posts from Stack Overflow or by arthurprs
Published on 2010-04-18T16:47:29Z Indexed on 2010/04/18 16:53 UTC
Read the original article Hit count: 371

$(".delete").click(
    function()  {
        var thesender = this;
        $(thesender).text("Del...");
        $.getJSON("ajax.php", {},
            function(data) {
                if (data["result"])
                    $(thesender).remove(); // variable defined outside
                else
                    alert('Error!');
            }
        );

        return false;
    }
);

This can cause problems if user clicks on another ".delete" before the ajax callback is called?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about anonymous-methods